#include <Arduino.h>

#define _595_DATA_INPUT 32
#define _595_STORE_DATA 33
#define _595_SYNC_DATA 25
#define _595_LIGHT_ENABLE 26

void Init_595()
{

    pinMode(_595_DATA_INPUT, OUTPUT);
    pinMode(_595_STORE_DATA, OUTPUT);
    pinMode(_595_SYNC_DATA, OUTPUT);
    pinMode(_595_LIGHT_ENABLE, OUTPUT);
}

void Write_595(int bits, int data)
{

    digitalWrite(_595_STORE_DATA, LOW);
    //delay(10);

    for (int i = 0; i < bits; i++)
    {
        if (data % 2 == 1)
        {
            digitalWrite(_595_DATA_INPUT, HIGH);
            //delay(10);
        }
        else
        {
            digitalWrite(_595_DATA_INPUT, LOW);
            //delay(10);
        }
        digitalWrite(_595_STORE_DATA, HIGH);
        //delay(10);
        digitalWrite(_595_STORE_DATA, LOW);
        //delay(10);
        data = data / 2;
    }
}

void Sync_595()
{
    digitalWrite(_595_SYNC_DATA, LOW);
    //delay(10);
    digitalWrite(_595_SYNC_DATA, HIGH);
    //delay(10);
    digitalWrite(_595_SYNC_DATA, LOW);
    //delay(10);
}

void Enable_595()
{
    digitalWrite(_595_LIGHT_ENABLE, LOW);
    //delay(10);
}

void Disable_595()
{
    digitalWrite(_595_LIGHT_ENABLE, HIGH);
    //delay(5);
}